//
//  GoodListCell.m
//  ReceiptDelivery
//
//  Created by 吕晶 on 2020/9/9.
//  Copyright © 2020 吕晶. All rights reserved.
//

#import "GoodListCell.h"

@interface GoodListCell ()

@property (nonatomic, strong) UIView *bgView;

@end

@implementation GoodListCell

+ (instancetype)GoodListCellWithTableView:(UITableView *)tableView {
    static NSString *cellID = @"GoodListCell";
    GoodListCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];
    if (cell == nil) {
        cell = [[GoodListCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID];
    }
    return cell;
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        self.backgroundColor = HexColor(0xffffff);
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        self.bgView = [UIView new];
        self.bgView.backgroundColor = HexColor(0xffffff);
        [self.contentView addSubview:self.bgView];
    }
    return self;
}

-(void)setDic:(NSArray *)dic {
    _dic = dic;
    [self configUI];
}

- (void)configUI {
//    NSArray *array = self.dic.allValues;
    self.bgView.nim_left = 0;
    self.bgView.nim_top = 0;
    self.bgView.nim_width = ScreenW * 0.25 * self.dic.count;
    [self.bgView.subviews makeObjectsPerformSelector:@selector(removeFromSuperview)];
    __block CGFloat viewHeight = 0;
    [self.dic enumerateObjectsUsingBlock:^(id  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
        UILabel *lab = [UILabel new];
        lab.textColor = HexColor(0x2B2C44);
        lab.font = [UIFont systemFontOfSize:14];
        lab.textAlignment = NSTextAlignmentCenter;
        lab.nim_left = ScreenW * 0.25 * idx;
        lab.nim_top = 15;
        lab.nim_width = ScreenW * 0.25;
        lab.nim_height = 15;
        lab.text = [NSString stringWithFormat:@"%@",obj];
        [self.bgView addSubview:lab];
        viewHeight = lab.nim_bottom + 15;
    }];
    self.bgView.nim_height = viewHeight;
    self.height = self.bgView.nim_bottom;
}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
